﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Diagnostics;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;

namespace 简单了解WinForm
{
    public partial class Form5 : Form
    {
        public Form5()
        {
            InitializeComponent();
        }

        private void Form5_FormClosing(object sender, FormClosingEventArgs e)
        {
            DialogResult dialogResult = MessageBox.Show("是否退出", "退出", MessageBoxButtons.OKCancel, MessageBoxIcon.Stop);
            if (dialogResult == DialogResult.Cancel)
            {
                e.Cancel = true;
            }
        }

        private void label1_Click(object sender, EventArgs e)
        {
            label1.Text = "标签被单击了";
        }

        private void linkLabel1_LinkClicked(object sender, LinkLabelLinkClickedEventArgs e)
        {
            Process.Start("https://www.bilibili.com/");
        }

        private void textBox1_TextChanged(object sender, EventArgs e)
        {
            label1.Text = textBox1.Text;
        }

        private void textBox3_MouseLeave(object sender, EventArgs e)
        {
            textBox3.PasswordChar = '*';
        }

        private void textBox3_MouseHover(object sender, EventArgs e)
        {
            textBox3.PasswordChar = '\0';
        }

        private void button_register_Click(object sender, EventArgs e)
        {
            string username = textBox2.Text;
            string password = textBox3.Text;
            string surePassword = textBox4.Text;
            if(string.IsNullOrEmpty(username))
            {
                MessageBox.Show("账号不能为空", "错误", MessageBoxButtons.OK, MessageBoxIcon.Error);
            }
            if(string.IsNullOrEmpty(password))
            {
                MessageBox.Show("密码不能为空", "错误", MessageBoxButtons.OK, MessageBoxIcon.Error);
            }
            if(!password.Equals(surePassword))
            {
                MessageBox.Show("密码和确认密码不一致", "错误", MessageBoxButtons.OK, MessageBoxIcon.Error);
            }
            else
            {
                MessageBox.Show($"注册成功，请记住账号: {username}, 密码: {password}", "注册成功", MessageBoxButtons.OK, MessageBoxIcon.Warning);
            }
        }

        private void textBox4_MouseHover(object sender, EventArgs e)
        {
            textBox4.PasswordChar = '\0';
        }

        private void textBox4_MouseLeave(object sender, EventArgs e)
        {
            textBox4.PasswordChar = '*';
        }
    }
}
